<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

//Validates an Input as a RFC2396 compliant URL
function isValidUrl($user_url) {
	//Uses php's filter_var function to find out http://www.faqs.org/rfcs/rfc2396 compliant URLs
	if (filter_var($user_url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)) {
		return TRUE;
	}

	return FALSE;
} //end function isValidUrl()

//finds out the domain name from the URL
function getDomain($user_url) {
	$url_parts = parse_url($user_url);
	return $url_parts['host'];
} //end function getDomain()

//check if the URL belongs to our domain
function isOurDomain($user_url) {
	if(strcmp(getDomain($user_url), getDomain(base_url())) == 0) {
		return TRUE;
	}

	return FALSE;
} //end isOurDomain()

//our valid url check using the other functions in this helper
function isMiniAsterValidUrl($user_url) {
	//checks that the domain of the URL is not our own domain (prevent url loops)
	//and that the url is a valid RFC 2396 URL.
	if(!isOurDomain($user_url) && isValidUrl($user_url)) {
		return TRUE;
	}

	return FALSE;
} //end function isMiniAsterValidUrl()
?>
